#!/usr/bin/env python
#coding=utf8
"""
@描述：按照对照关系将智联/51job/猎聘等插入到数据库中
@日期：2015年01月28日 星期三

@作者：hongxingfan
"""

import MySQLdb
import sys


def openConn():
	conn = MySQLdb.connect(host="192.168.1.251",user="root",passwd="",db="jobs",charset="utf8")
	return conn

if __name__ == "__main__":
	conn = openConn()
	insert = "INSERT INTO otherSiteToKanZhun(siteName,NAME,thirdId) VALUES(%s,%s,%s)"
	cursor = conn.cursor()
	#f = open(r"/cygdrive/c/Users/wenxiubi/Documents/zhilian.txt")
	#f = open(r"/cygdrive/c/Users/wenxiubi/Documents/51job.txt")
	f = open(r"/cygdrive/c/Users/wenxiubi/Documents/liepin.txt")
	#siteName = "zhilian"
	#siteName = "51job"
	siteName = "liepin"
	for line in f:
		line = line.strip()
		cols = line.split("\t")
		thirdId = cols[0] # thirdId
		for col in cols[1:]:
			if col == "" or col == "其他":
				continue
			name = col
			try:
				cursor.execute(insert,(siteName,name,thirdId))
				print("OK\t" + siteName + "\t" + name + "\t" + thirdId)
			except:
				print("Error\t" + siteName + "\t" + name + "\t" + thirdId)
				sys.exit(0)
		conn.commit()
	conn.close()
